/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.element.steuer.rollbar.gruppe;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Listener;

import de.mnit.basis.fehler.Fehler;

/**
 * @author Michael Nitsche
 */
public class SWT_Auswahl extends A_SWT_Gruppe<SWT_Auswahl,Combo> {

	private boolean leer=true;


	// FUNKTION

	public SWT_Auswahl s1_NurLesbar() {
		this.PN_Erzeugt();
		this.s1_Style(SWT.READ_ONLY);
		return this;
	}

	public SWT_Auswahl sText(String text) {
		leer=false;
		swt().setText(text);
		return this;
	}

	public SWT_Auswahl plus(String... eintrag) {
		Fehler.objekt.wenn_Null((Object)eintrag);
		for(String t : eintrag) {
			swt().add(t);
			if(leer)
				leer=false; sText(t);
		}
		return this;
	}

	public SWT_Auswahl leeren() {
		swt().removeAll();
		leer=true;
		return this;
	}

	// LESEN

	public String gText() {
		return swt().getText();
	}

	// EVENT

	/** Wird erst mit "" ausgelöst, wenn neue Auswahl */
	public SWT_Auswahl eGeaendert(Listener l) {
		swt().addListener(SWT.Modify,l);
		return this;
	}

	// ERZEUGEN

	protected int style5() {
		return SWT.NONE;
	}

	protected Combo roh(Composite basis, int style) {
		return new Combo(basis,style);
	}

	protected void init5() {
	}

}